# 0-1背包问题
content = 150
bag = []
bag_weight = 0
bag_price = 0
weight_dict = {1: 35, 2: 30, 3: 60, 4: 50, 5: 40, 6: 10, 7: 25}
price_dict = {1: 10, 2: 40, 3: 30, 4: 50, 5: 35, 6: 40, 7: 30}


# 找出价格最高的物品：
def find_weight():
    obj = None
    obj_price = 0
    for price in price_dict.items():
        if price[1] > obj_price:
            obj = price[0]
            obj_price = price[1]
    find_obj = (obj, price_dict.pop(obj))
    return find_obj


def q_bag(func):
    global content, bag_price, bag_weight
    while price_dict:
        find_o = func()
        if weight_dict[find_o[0]] < content:
            content -= weight_dict[find_o[0]]
            bag.append(find_o[0])
            bag_price += find_o[1]
            bag_weight += weight_dict[find_o[0]]
    print("选出物品的序号为%s，总重量为%d，总价格为%d" % (bag, bag_weight, bag_price))

q_bag(find_weight)
